emial = false;
nickname = false;
pwd1 = false;
pwd2 = false;
vcode = false;
$(function(){
	//验证邮箱输入
	$("#txtEmail").blur(function(){
		//判空
		if($("#txtEmail").val().length == 0){ emial = false; $("#emailinfo").text(""); $("#emailinfo").text("邮箱不能为空！");}
		//格式判断
		else if(email($("#txtEmail").val())){ email = true; $("#emailinfo").text(""); $("#emailinfosuccess").text("邮箱格式正确！");}
		else{ emial = false; $("#emailinfo").text(""); $("#emailinfo").text("邮箱格式不正确!");}
	});
	$("#txtNickName").blur(function(){
		//判空
		if($("#txtNickName").val().length == 0){$("#nameinfo").text(""); $("#nameinfo").text("用户昵称不能为空"); nickname = false;}
		else if(vickname($("#txtNickName").val())){$("#nameinfo").text("");  $("#nameinfosuccess").text("昵称可用!"); nickname = true;}
		else{$("#nameinfo").text(""); $("#nameinfo").text("昵称格式不对！"); nickname = false;}
	});
	$("#txtPassword").blur(function(){
		var pattern=/^[a-z0-9A-Z]{6,20}$/;
		if(pattern.test($("#txtPassword").val())){$("#passwordinfo").text("");pwd1 = true;}
		else{
			$("#passwordinfo").text("");
			$("#passwordinfo").text("密码格式错误！");
			pwd1 = false;
		}
	});
	//验证两次输入是否一致
	$("#txtRepeatPass").blur(function(){
	if($("#txtPassword").val()== $("#txtRepeatPass").val()){
		$("#password1info").text("");
		pwd2 = true;
	}else{$("#password1info").text("密码输入不一致！"); pwd2 = false;}
	});
	//验证验证码
	$("#txtVerifyCode").blur(function(){
		$.ajax({
			type:"post",
			data:{vcode:$("#txtVerifyCode").val()},
			url:"<s:url action='checkVcode'/>",
			success:function(result){
				if(result == "t"){
					$("#numberinfo").text("");
				}else{
					
					$("#numberinfo").text("验证码输入错误！");
				}
			}
		});
	})
});
/**
 * 邮箱验证
 */
function email(email) {
	email=email.trim();
	if(email.length==0) {
		return true;
	}
	var pattern=/\b(^['_A-Za-z0-9-]+(\.['_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\.[A-Za-z0-9-]+)*((\.[A-Za-z0-9]{2,})|(\.[A-Za-z0-9]{2,}\.[A-Za-z0-9]{2,}))$)\b/;
	if(regex(email,pattern,false)) {
		return true;
	}
	else {
		return false;
	}
}
/**
 * 验证昵称
 */
function vickname(vickname){
	vickname = vickname.trim();
	/*if(vickname==0){
		return true;
	}*/
	//长度
	if(vickname<21 && vickname>3){
		return false;
	}
	var pattern=/^([\u4E00-\u9FA5]{2,10})|[a-z0-9]{4,20}|[\u4E00-\u9FA5]{1,10}[a-z0-9]{2,20}$/;
	if(regex(vickname,pattern,false))
		return true;
	else
		return false;
}
/**
 * 验证密码是否合法
 */
function password(password){
	password = password.trim();
	//正则表达式控制非法字符       
	var pattern=/^[a-z0-9A-Z]{6,20}$/;
	if(regex(vickname,pattern,false))
		return true;
	else
		return false;
}